<?php

class UploadController
{
    public function __construct()
    {
        $items = [];
        $files = Utils::upload($_FILES, App::$siteroot . "/data");
        if (empty($files) == false) {
            $c = Connector::share()->reset();
            foreach ($files as $path => $type) {
                $item["image"] = Image::resize($path, 400, 400);
                $item["thumb"] = Image::resize($path, 200, 200);
                $item["type"] = $type;
                $item["path"] = $path;
                if ($c->insert("asset", $item) > 0) {
                    $item["id"] = $c->getId();
                    $items[] = $item;
                }
            }
        }

        if (count($items) > 0){
            Utils::print(0, $items);
        }

        echo <<<EOT
    <form action="" enctype="multipart/form-data" method="post" name="uploadfile">
    上传文件：<br>
    <input type="file" name="upfile[]" /><br>
    <input type="file" name="upfile[]" /><br>
    <input type="submit" value="上传" />
    </form>
EOT;
    }
}